﻿@inherits BaseComponent

<SettingTypeForm Class="kui-setting-form" Model="Context.UserSetting" LabelColSpan="6" OnFinish="OnSave">
    <Title Level="4">@Language["Set.ThemeSetting"]</Title>
    <div class="kui-theme-color">
        @foreach (var item in Colors)
        {
            <div class="item" style="background-color:@(item.Value)" @onclick="e=>OnThemeColor(item.Key)">
                @if (context.ThemeColor == item.Key)
                {
                    <Icon Type="check" />
                }
            </div>
        }
    </div>
    <FormItem Label="@Language["Set.Menu"]">
        <AntRadioGroup @bind-Value="context.MenuTheme" Codes="MenuThemes" OnChange="OnChange" />
    </FormItem>
    <Divider />
    <Title Level="4">@Language["Set.LayoutSetting"]</Title>
    <FormItem Label="@Language["Set.Layout"]">
        <AntRadioGroup @bind-Value="context.LayoutMode" Codes="LayoutModes" OnChange="OnChange" />
    </FormItem>
    <FormItem Label="@Language["Set.Tabs"]">
        <Switch @bind-Checked="context.MultiTab" OnChange="OnChange" />
    </FormItem>
    @if (context.MultiTab)
    {
        <FormItem Label="@Language["Set.TopTab"]">
            <Switch @bind-Checked="context.IsTopTab" OnChange="OnChange" />
        </FormItem>
        <FormItem Label="@Language["Set.MaxTabCount"]">
            <AntInteger @bind-Value="context.MaxTabCount" />
        </FormItem>
    }
    <Divider />
    <Title Level="4">@Language["Set.PreferenceSetting"]</Title>
    <FormItem Label="@Language["Set.Accordion"]">
        <Switch @bind-Checked="context.Accordion" OnChange="OnChange" />
    </FormItem>
    <FormItem Label="表单">
        <AntRadioGroup @bind-Value="context.OpenType" Category="@nameof(FormOpenType)" />
    </FormItem>
    <Title Level="4">@Language["Set.RegionalSetting"]</Title>
    <FormItem Label="@Language["Set.Footer"]">
        <Switch @bind-Checked="context.ShowFooter" OnChange="OnChange" />
    </FormItem>
    <FormItem WrapperColOffset="6" WrapperColSpan="16">
        <Button Type="@ButtonType.Primary" HtmlType="submit">@Language.Save</Button>
        <Button OnClick="OnResetAsync">@Language.Reset</Button>
    </FormItem>
</SettingTypeForm>

@code {
    private Dictionary<string, string> Colors = new Dictionary<string, string>
    {
        ["default"] = "#1890ff",
        ["dust"] = "#F5222D",
        ["volcano"] = "#FA541C",
        ["sunset"] = "#FAAD14",
        ["cyan"] = "#13C2C2",
        ["green"] = "#52C41A",
        ["geekblue"] = "#2F54EB",
        ["purple"] = "#722ED1"
    };
    private List<CodeInfo> MenuThemes => [
        new CodeInfo("Dark", Language["Set.Dark"]),
    new CodeInfo("Light", Language["Set.Light"])
    ];
    private List<CodeInfo> LayoutModes => [
        new CodeInfo("Vertical", Language["Set.Vertical"]),
    new CodeInfo("Horizontal", Language["Set.Horizontal"]),
    new CodeInfo("Float", Language["Set.Float"])
    ];

    [Parameter] public Action OnChange { get; set; }
    [Parameter] public Func<Task> OnSave { get; set; }
    [Parameter] public Func<Task> OnReset { get; set; }

    private async Task OnThemeColor(string theme)
    {
        Context.UserSetting.ThemeColor = theme;
        var href = $"_content/Known/css/theme/{theme}.css";
        await JS.SetStyleSheetAsync("/theme/", href);
    }

    private async Task OnResetAsync()
    {
        if (OnReset != null)
        {
            await OnReset.Invoke();
            await StateChangedAsync();
            OnChange?.Invoke();
        }
    }
}